from collections import Iterable

# 构造1-100的列表
# 方案一：
L1 = []
n = 1
while n < 100:
    L1.append(n)
    n += 2
print(L1)
# 方案二：
# L2 = []
# for i in range(1, 100, 2):
#     L2.append(i)
# print(L2)

# 类似java substring
# list切片
print(L1[0:3])  # 取下标0-2的值
print(L1[0:10:2])  # 取下标0-9的值 步长2

# 元祖切片
L_turple = (1, 2, 3, 4, 5, 6, 7, 8, 9)
print(L_turple[0:2])
print(L_turple[0:8:2])
print(L_turple[::2])

# 字符切片
str = '123456789'
print(str[0:6])
print(str[0:6:2])

# 判断一个对象是否可迭代
str = 'abc'
isinstance(str, Iterable)

# 列表生成式
print([x * b for x in range(1, 11) for b in range(1, 11)])
